package com.rede.didiok.user.web;

import java.util.Map;

import javax.annotation.Resource;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.enums.StatusEnum;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.dto.user.UserCountResultDto;
import com.rede.didiok.user.service.UserService;
import com.rede.didiok.user.service.WebVisitService;

/**
 * @Author: Rede
 * @DateTime: 2023-08-31 20:05
 * @Description: 首页 RestApi
 */
@RestController
@RequestMapping("user/feign/index")
public class UserIndexController {

    @Resource
    private UserService userService;

    @Resource
    private WebVisitService webVisitService;

    /**
     * 获取总记录数
     *
     * @return
     */
    @GetMapping("/getTotalCount")
    String getTotalCount(){
        UserCountResultDto resultDto = new UserCountResultDto();
        // 用户的数量
        Integer userCount = userService.getUserCount(StatusEnum.ENABLE);
        resultDto.setUserCount(String.valueOf(userCount));

        // 获取今日网站访问人数
        Integer webVisitCount = webVisitService.getWebVisitCount();
        resultDto.setWebVisitCount(String.valueOf(webVisitCount));

        return ResultUtil.successWithData(resultDto);
    }

    @ApiOperation(value = "获取最近一周用户独立IP数和访问量", notes = "获取最近一周用户独立IP数和访问量", response = String.class)
    @RequestMapping(value = "/getWebVisitByWeek", method = RequestMethod.GET)
    public String getWebVisitByWeek() {
        Map<String, Object> visitByWeek = webVisitService.getWebVisitByWeek();
        return ResultUtil.result(SysConf.SUCCESS, visitByWeek);
    }

}
